package com.CTAtracker.android.Adapters;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.CTAtracker.android.R;
import com.CTAtracker.android.Models.Station;

/**
 * This class is a adapter for the searched 
 */
public class StationsSearchItemAdapter extends ArrayAdapter<Station> {
	
	/**
	 * The layout to inflate
	 */
	private LayoutInflater _layoutInflater = null;
	/**
	 * The id of the resource
	 */
	private int _resourceId = 0;
	/**
	 * The list of station to adapt to the view
	 */
	private ArrayList<Station> _listStations;

	/**
	 * Constructor of the class. Instance the attribute and call the super method.
	 * @param context The context of the application
	 * @param resourceId The id of the resource to inflate 
	 * @param objects the list of station to adapt to the view
	 */
	public StationsSearchItemAdapter(Context context, int resourceId, List<Station> objects) {
		super(context, resourceId, 0, objects);

		_layoutInflater = LayoutInflater.from(context);
		_resourceId = resourceId;
		_listStations = (ArrayList<Station>) objects;
	}

	/**
	 * This method is call every time we want to display the view
	 * Display the list of station
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final Station station = _listStations.get(position);
		convertView = _layoutInflater.inflate(_resourceId, parent, false);

		TextView tvn = (TextView) convertView.findViewById(R.id.textViewStationSearch);
		tvn.setText(station.get_name());

		return convertView;
	}
}
